package top.codecrab.eblog.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.codecrab.eblog.common.response.R;
import top.codecrab.eblog.config.Constants;
import top.codecrab.eblog.im.vo.ImUser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chat")
public class ChatController extends BaseController {

    @GetMapping("/getMineAndGroupData")
    public R getMineAndGroupData() {
        //默认群
        Map<String, Object> group = new HashMap<>();
        group.put("name", "社区群聊");
        group.put("type", "group");
        group.put("avatar", "https://bamboo-smoke-img.oss-cn-shanghai.aliyuncs.com/logo/bamboo-smoke.png");
        group.put("id", Constants.IM_GROUP_ID);
        group.put("members", 0);

        ImUser user = chatService.getCurrentUser();
        return R.ok().put("group", group).put("mine", user);
    }

    @GetMapping("/getGroupHistoryMsg")
    public R getGroupHistoryMsg() {
        List<Object> messages = chatService.getGroupHistoryMsg(100);
        return R.ok(messages);
    }

    @GetMapping("/tioServerUrl")
    public R getTioServerUrl() {
        String host = eblogProperties.getImServer().getHost();
        int port = eblogProperties.getImServer().getPort();
        return R.ok(host + ":" + port);
    }

}
